package com.spring.boot.rabbit.components;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * 默认的消息回复回调函数
 * <p>
 * 当交换机路由到队列失败时触发
 *
 * @author 李坤
 * @date 2022/9/1 16:38
 */
@Component
public class DefaultReturnCallback implements RabbitTemplate.ReturnCallback {

    /**
     * 日志处理器
     */
    private final Logger logger = LoggerFactory.getLogger(DefaultReturnCallback.class);

    @Override
    public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        logger.info("消息回复-回复代码: {}", replyCode);
        logger.info("消息回复-回复内容: {}", replyText);
        logger.info("消息回复-交换机: {}", exchange);
        logger.info("消息回复-路由键: {}", routingKey);
        logger.info("消息回复-消息: {}", message.toString());
    }
}
